<template>
  <div v-loading="loading">
    <healthView ref="healthView" :list="list" is-btn @setHealthValue="setHealthValue" />
    <collectionShow v-if="hasRouteAuth('crm:accounts:collectManage')"/>
    <unpublishedNotice />
    <energyType ref="energyTypeRef" @queryAllTypes="queryAllTypes" />
    <projectType ref="projectTypeRef" @queryAllTypes="queryAllTypes" />
    <sensitiveWords/>
  </div>
</template>

<script>
import healthView from '@/components/HealthValue/healthView';
import collectionShow from './components/collectionShow';
import unpublishedNotice from './components/unpublishedNotice';
import energyType from './components/energyType';
import projectType from './components/projectType';
import sensitiveWords from './components/sensitiveWords';

import { setDefaultHealthValue, getDefaultHealthValue } from '@/api/accounts';
import { hasRouteAuth } from '@/utils/permission';

export default {
  components: { healthView, collectionShow, unpublishedNotice, energyType, projectType, sensitiveWords },
  data() {
    return {
      list: [],
      loading: false
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    hasRouteAuth,
    fetchData() {
      this.loading = true;
      getDefaultHealthValue().then(res => {
        if (res.code === 200) {
          this.list = res.data;
          this.loading = false;
        }
      }, _ => {
        this.loading = false;
      }).catch(err => {
        this.$message.error(err.message);
      });
    },
    setHealthValue(data) {
      setDefaultHealthValue({ data }).then(res => {
        if (res.code === 200) {
          this.$message.success('操作成功');
          this.$refs['healthView'].handleClose();
          this.fetchData();
        }
      }).catch(err => {
        this.$message.error(err.message);
      });
    },
    queryAllTypes() {
      this.$refs['energyTypeRef'] && this.$refs['energyTypeRef'].fetchData();
      this.$refs['projectTypeRef'] && this.$refs['projectTypeRef'].fetchData();
    }
  }
};
</script>

<style lang="scss" scoped>
.health-view {
  font-size: 14px;
  &::v-deep {
    .health-left {
      &.label {
        color: #333;
        font-weight: 600;
      }
    }
  }
}
</style>
